Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update api-authentication.md #2

Closed
wants to merge 2 commits into from
Closed

Update api-authentication.md #2

wants to merge 2 commits into from

Conversation

mro
Copy link

@mro mro commented Jun 15, 2016

No description provided.

@ArthurHoaro
Copy link
Member

  • 1.: Would be highly insecure, because it would require every request to carry the password.
  • OAuth2 or Kerberos: these are complex protocols, IMHO too complex for what where trying to do here.

So I'm also in favor of a token + secret salt system. That's what have been proposed in shaarli/Shaarli#586. But I'm more in favor of using JWT because it's widely used and there are existing library for clients in any language.

@mro
Copy link
Author

mro commented Jun 15, 2016

existing library for clients

what library would one need to simply set a header?

@mro
Copy link
Author

mro commented Jun 15, 2016

and: why should we parse the request payload (json), if we can tell by the header it's not authenticated? JWT appears over-engineered to me (for our purpose).

@ArthurHoaro
Copy link
Member

ArthurHoaro commented Jun 15, 2016

Because if you only use one hash in the header, I can forge any request if I get your hash (which is contained in every requests).

@virtualtam
Copy link
Member

virtualtam commented Jun 15, 2016

Why not stick with login/password authentication to begin with?

When emitting several requests over an HTTP service that requires authentication, one usually:

  • opens an HTTP session with a first request carrying the credentials,
  • reuses this session to send further requests

Then, once an API is well-defined, new means of authentication can be added (e.g. easily renewable/revokable tokens)

@ArthurHoaro
Copy link
Member

That's the exact opposite of what a stateless API should be. While scalability isn't really important for Shaarli, I don't think that creating an authentication service, checking client state, handling logout and reconnections is easier to do than using hash and base64_encode to check a token validity.

@mro
Copy link
Author

mro commented Jun 15, 2016

don't forget about the client complexity, too.

@ArthurHoaro
Copy link
Member

ArthurHoaro commented Jun 15, 2016

Here is what a client should do to generate a valid JWT token if we use one hashing algorithm (PHP example):

generateToken($secret, $data) {
  $header = base64_encode(json_encode([ 'alg' => 'HS256', 'typ': 'JWT' ]));
  $body = base64_encode(json_encode($data));
  $signature = hash('sha256', $header .'.'. $body .'.'. $secret);
  return $header .'.'. $body .'.'. $signature;
}

And eventually add a timestamp in the body or header to "burn" the token. With this method neither the password or the 'secret' go through requests.

I believe this method has a good security/complexity balance.

@mro
Copy link
Author

mro commented Jun 15, 2016

holy shit.

@mro mro mentioned this pull request Jun 15, 2016
@mro mro closed this Jun 16, 2016
@mro
Copy link
Author

mro commented Jun 16, 2016

wanted a wiki-edit, not a PR. So closing.

@mro
Copy link
Author

mro commented Jun 16, 2016

may be ninja-re-opened once #6 is clarified.

@ArthurHoaro ArthurHoaro mentioned this pull request Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants